Flexible Immutability with Frozen Objects
نویسندگان
چکیده
Object immutability is a familiar concept that allows safe sharing of objects. Existing language support for immutability is based on immutable classes. However, class-based approaches are restrictive because programmers can neither make instances of arbitrary classes immutable, nor can they control when an instance becomes immutable. These restrictions prevent many interesting applications where objects of mutable classes go through a number of modifications before they become immutable. This paper presents a flexible technique to enforce the immutability of individual objects by transferring their ownership to a special freezer object, which prevents further modification. The paper demonstrates how immutability facilitates program verification by extending the Boogie methodology for object invariants to immutable objects. The technique is based on Spec#’s dynamic ownership, but the concepts also apply to other ownership systems that support transfer.
منابع مشابه
Type-Based Object Immutability with Flexible Initialization
We present a type system for checking object immutability, read-only references, and class immutability in an open or closed world. To allow object initialization outside object constructors (which is often needed in practice), im mutable objects are initialized in lexically scoped regions. The system is simple and direct; its only type qualifiers specify immutability properties. No auxiliary...
متن کاملImmutable Objects for a Java-Like Language
We extend a Java-like language with immutability specifications and a static type system for verifying immutability. A class modifier immutable specifies that all class instances are immutable objects. Ownership types specify the depth of object states and enforce encapsulation of representation objects. The type system guarantees that the state of immutable objects does not visibly mutate duri...
متن کاملImmutable Objects in Java
Immutability is a very useful and desirable property for objects. This paper investigates different possible notions of immutability for Java objects, to find out which notion is the most intuitive and useful, both when it comes to ways of enforcing immutability of objects, and when it comes to exploiting information about (im)mutability of objects in program verification and in various static ...
متن کاملRelaxing Ownership with Immutability
Multiple ownership [4] introduced a novel approach to managing object ownership information called “owners-as-boxes”. Each object is placed in a “box” or context and the nesting relationship between “boxes” or contexts respects the object accesses that happen during the program’s execution. No restrictions are placed on which objects are allowed to access which other objects, rather the ownersh...
متن کاملRely-Guarantee References for Refinement Types
Reasoning about side effects and aliasing is the heart of verifyingimperative programs. Unrestricted side effects through one refer-ence can invalidate assumptions about an alias. We present a newtype system approach to reasoning about safe assumptions in thepresence of aliasing and side effects, unifying ideas from referenceimmutability type systems and rely-guarantee progr...
متن کامل